package com.meihuak.cloud_ordering.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meihuak.cloud_ordering.bean.OrderChild;
import com.meihuak.cloud_ordering.mapper.OrderChildMapper;
import com.meihuak.cloud_ordering.service.DishService;
import com.meihuak.cloud_ordering.service.OrderChildService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 韩迪
 * @date 2022/03/26 16:24
 **/
@Service
public class OrderChildServiceImpl extends ServiceImpl<OrderChildMapper, OrderChild> implements OrderChildService{
   @Autowired
   OrderChildService childService;
   @Autowired
    DishService dishService;

    /**
     * 通过OrderId查询
     *
     * @param id
     */
    @Override
    public List<OrderChild> getOrderChiledByOrderId(long id) {
        QueryWrapper<OrderChild> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id",id);
        return childService.list(queryWrapper);
    }

    @Override
    public int getFinishTime(Long id) {
        OrderChild child = this.getById(id);
        return dishService.getDishFinishTimeById(child.getDishId())*child.getCount();
    }

    /**
     * 获取order完成时间
     *
     * @param id
     */
    @Override
    public int getOrderFinishTimeById(Long id) {
        QueryWrapper<OrderChild> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id",id);
        List<OrderChild> childList = this.list(queryWrapper);
        int time=0;
        for(OrderChild child:childList){
            time+=this.getFinishTime(child.getId()) ;
        }
        return time;
    }

}
